package org.springframework.samples.mvc.basic.gotovproizvod;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.samples.mvc.basic.business.AbstractBusinessService;
import org.springframework.samples.mvc.basic.business.Transformer;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.proba.annotations.GotovProizvodDAO;
import com.proba.annotations.pojo.GotovProizvod;

@Service
public class GotovProizvodBusinessServiceImpl extends AbstractBusinessService<GotovProizvod, GotovProizvodView> implements GotovProizvodBusinessService {

	@Autowired
	private GotovProizvodDAO dao;
	private GotovProizvodTransformer transformer = new GotovProizvodTransformer();

	@Override
	@Transactional
	public List<GotovProizvodView> findAll(int startIndex, int pageSize,
			GotovProizvodView queryInfo) {
		List<GotovProizvod> res = dao.findByFilterParams(startIndex, pageSize, queryInfo.getId(), queryInfo.getEdinicaMerka(), queryInfo.getGotovProizvod(), queryInfo.getTipGotovProizvod());
		return transform(res);
	}

	@Override
	protected GotovProizvodDAO getDao() {
		return dao;
	}

	@Override
	protected Transformer<GotovProizvod, GotovProizvodView> getTransformer() {
		return transformer;
	}

	@Override
	public List<GotovProizvodView> getByEdinicaMerkaId(int startIndex, int pageSize, Long edinicaMerka) {
		List<GotovProizvod> res = dao.findByEdinicaMerka(startIndex, pageSize, edinicaMerka);
		return transform(res);
	}

	@Override
	public int countByEdinicaMerka(Long edinicaMerkaId) {
		return dao.countByEdinicaMerka(edinicaMerkaId);
	}

}
